package com.sjl.interceptor;

import com.sjl.pojo.SysUser;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {
   public   boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
           throws Exception {
       HttpSession session = request.getSession();
       SysUser user = (SysUser) session.getAttribute("USER_SESSION");
       if(user==null){
           response.sendRedirect(request.getContextPath()+"/user/to_login");
           return false;
       }


       return true;
    }
}
